package com;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

// Customer 类表示客户
class Customer {
    private String name;
    private String contact;
    private String deliveryAddress;
    private boolean active;

    public Customer(String name, String contact, String deliveryAddress, boolean active) {
        this.name = name;
        this.contact = contact;
        this.deliveryAddress = deliveryAddress;
        this.active = active;
    }

    // getters and setters
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getDeliveryAddress() {
        return deliveryAddress;
    }

    public void setDeliveryAddress(String deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }
}

// Order 类表示订单
class Order {
    private Date createDate;
    private String status;
    private List<OrderDetail> orderDetails;

    public Order(Date createDate, String status) {
        this.createDate = createDate;
        this.status = status;
        this.orderDetails = new ArrayList<>();
    }

    public void addOrderDetail(OrderDetail orderDetail) {
        orderDetails.add(orderDetail);
    }

    public List<OrderDetail> getOrderDetails() {
        return orderDetails;
    }

    // getters and setters
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}

// OrderDetail 类表示订单详情
class OrderDetail {
    private int quantity;
    private Product product;

    public OrderDetail(int quantity, Product product) {
        this.quantity = quantity;
        this.product = product;
    }

    public double calculateSubTotal() {
        return quantity * product.getPriceForQuantity(quantity);
    }

    public double calculateWeight() {
        return quantity * product.getWeight();
    }

    // getters and setters
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }
}

// Product 类表示产品
class Product {
    private String title;
    private double weight;
    private String description;

    public Product(String title, double weight, String description) {
        this.title = title;
        this.weight = weight;
        this.description = description;
    }

    public double getPriceForQuantity(int quantity) {
        // Simple pricing strategy: no discount
        return weight * 2; // Example price calculation
    }

    public double getWeight() {
        return weight;
    }

    // getters and setters
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}

// Payment 类表示支付
abstract class Payment {
    protected double amount;

    public Payment(double amount) {
        this.amount = amount;
    }

    // getters and setters
    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }
}

// Cash 类表示现金支付
class Cash extends Payment {
    private double cashTendered;

    public Cash(double cashTendered) {
        super(cashTendered);
        this.cashTendered = cashTendered;
    }

    // getters and setters
    public double getCashTendered() {
        return cashTendered;
    }

    public void setCashTendered(double cashTendered) {
        this.cashTendered = cashTendered;
    }
}

// Alipay 类表示支付宝支付
class Alipay extends Payment {
    private String number;

    public Alipay(double amount, String number) {
        super(amount);
        this.number = number;
    }

    // getters and setters
    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }
}

// Credit 类表示信用卡支付
class Credit extends Payment {
    private String number;
    private String type;
    private Date expireDate;

    public Credit(double amount, String number, String type, Date expireDate) {
        super(amount);
        this.number = number;
        this.type = type;
        this.expireDate = expireDate;
    }

    // getters and setters
    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Date getExpireDate() {
        return expireDate;
    }

    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }
}

// WeixinPay 类表示微信支付
class WeixinPay extends Payment {
    private String weixinPay;

    public WeixinPay(double amount, String weixinPay) {
        super(amount);
        this.weixinPay = weixinPay;
    }

    // getters and setters
    public String getWeixinPay() {
        return weixinPay;
    }

    public void setWeixinPay(String weixinPay) {
        this.weixinPay = weixinPay;
    }
}

// WireTransfer 类表示电汇支付
class WireTransfer extends Payment {
    private String bankID;
    private String bankName;

    public WireTransfer(double amount, String bankID, String bankName) {
        super(amount);
        this.bankID = bankID;
        this.bankName = bankName;
    }

    // getters and setters
    public String getBankID() {
        return bankID;
    }

    public void setBankID(String bankID) {
        this.bankID = bankID;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }
}

public class A1_4 {
    public static void main(String[] args) {
        // 创建客户实例
        Customer customer = new Customer("John Doe", "1234567890", "123 Main St", true);

        // 创建订单实例
        Order order = new Order(new Date(), "Pending");

        // 创建产品实例
        Product product = new Product("Laptop", 2.5, "A high-performance laptop");

        // 创建订单详情实例
        OrderDetail orderDetail = new OrderDetail(1, product);

        // 将订单详情添加到订单
        order.addOrderDetail(orderDetail);

        // 创建支付实例
        Cash cash = new Cash(1000.0);
        Alipay alipay = new Alipay(1000.0, "123456789");
        Credit credit = new Credit(1000.0, "1234567890123456", "Visa", new Date(2025, 11, 30));
        WeixinPay weixinPay = new WeixinPay(1000.0, "wx123456789");
        WireTransfer wireTransfer = new WireTransfer(1000.0, "12345", "Moonshot Bank");

        // 打印信息
        System.out.println("Customer Name: " + customer.getName());
        System.out.println("Order Status: " + order.getStatus());
        System.out.println("Order Total: " + orderDetail.calculateSubTotal());
        System.out.println("Payment Method: Cash, Amount: " + cash.getAmount());
        System.out.println("Payment Method: Alipay, Number: " + alipay.getNumber());
        System.out.println("Payment Method: Credit, Number: " + credit.getNumber());
        System.out.println("Payment Method: WeixinPay, WeixinPay: " + weixinPay.getWeixinPay());
        System.out.println("Payment Method: WireTransfer, BankID: " + wireTransfer.getBankID());
    }
}